<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <div class="nav">弈- 多人在线五子棋pk系统</div>
    <div class="login">
        <div class="login-box">
            <h3>欢迎玩家登录</h3>
            <div class="row">
                <span>用户名:</span>
                <input type="text" id="userName">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" id="password">
            </div>
            <div class="row">
                <button id="submit" onclick="login()">提交</button>
            </div>
            <div class="row">
                <button id="submit" onclick="register()">注册账号</button>
            </div>
        </div>
    </div>


    <script>
        function register() {
            location.href = "user_register.html"
        }
        function login() {
            $.ajax({
                url: "/user/login",
                type: "post",
                data: {
                    userName: $("#userName").val(),
                    password: $("#password").val()
                },
                success: function (data) {

                    if (data.code == "SUCCESS") {
                        console.log("登录成功");
                        // alert("登录成功");
                        location.href = "game_hub.html";
                    } else alert(data.errMsg);

                },
                error: function (data) {

                }
            })
        }
    </script>

</body>

</html>